﻿
Imports System.Data.SqlClient
Public Class Frm_idafat_mokhabara
    'Remplir le comboBox par le nom et le prenom avec un id
    Public Sub remplirMokhabara()
        Partager.moi.remplir_List_mokhabara()

        Dim htClient As New Hashtable()
        Dim str As String = ""
        For Each clt As Avocat_mokhabara In Partager.moi.List_mokhabara
            str = clt.Nom_a & "  " & clt.Prenom_a
            htClient.Add(clt.Id, str)
        Next

        For Each ImageType As DictionaryEntry In htClient
            Comb_nom_mokhabara.Items.Add(ImageType)
        Next
        Comb_nom_mokhabara.DisplayMember = "value"
        Comb_nom_mokhabara.ValueMember = "key"
        If Comb_nom_mokhabara.Items.Count > 0 Then
            Comb_nom_mokhabara.SelectedIndex = 0
        End If
    End Sub

    'Remplir le comboBox par le nom et le prenom avec un id
    Public Sub remplirMaListMokhabara()
        partager.dv.remplir_List_Dos_Avo_Bur_Mokh(Partager.idAvoDoss)
        List_tous.Items.Clear()
        Dim ListViewItem1 As System.Windows.Forms.ListViewItem
        Dim Str As String = ""

        For Each avo As Avocat_mokhabara In Partager.moi.List_mokhabara
            For Each dossAvo As dossier_Avocat_Mokhabara In partager.dv.List_Mokhabara
                If avo.Id = dossAvo.Id_Avocat_Mokh Then

                    ListViewItem1 = New System.Windows.Forms.ListViewItem(New String() {"", avo.Num_Prof, avo.Nom_a, avo.Prenom_a}, -1)
                    'il est indispensable d'ajouter chekHand false et true
                    Partager.checkHand = False
                    If dossAvo.nomme Then
                        ListViewItem1.Checked = True
                    Else
                        ListViewItem1.Checked = False
                    End If
                    Me.List_tous.Items.AddRange(New System.Windows.Forms.ListViewItem() {ListViewItem1})
                    Partager.checkHand = True
                End If
            Next
        Next
    End Sub
    Private Sub btn_rech_nom_mokhabara_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_rech_nom_mokhabara.Click
        Me.Enabled = False
        Frm_Rech_Avoc_mokhabara.Show()
        Partager.type = "Frm_idafat_mokhabara"
    End Sub

    Private Sub btn_parc_jiha_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Frm_idafat_mokhabara_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_Idafa_Mowakilin.Enabled = True
        Frm_Av_Mowakil.Enabled = True
        Frm_Av_Mowakil.TopMost = True
    End Sub

    Private Sub Frm_idafat_mokhabara_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        List_tous.Columns(0).DisplayIndex = List_tous.Columns.Count - 1
        txt_marji3ona.Text = partager.dv.Num
        txtNom.Text = Partager.nomMohami
        remplirMokhabara()
        remplirMaListMokhabara()
        Me.BringToFront()
    End Sub
    Dim dossAvo As dossier_Avocat_Mokhabara
    Private Sub Btn_ajout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_ajout.Click
        Try
            If Comb_nom_mokhabara.Text <> "" Then

                If MsgBox("هل تريد فعلا إضافة هذا المحامي لهذا الملف ؟", MsgBoxStyle.YesNo Or MsgBoxStyle.Information, "إضافة") = MsgBoxResult.Yes Then
                    Partager.close()

                    Partager.deClt = DirectCast(Comb_nom_mokhabara.SelectedItem, DictionaryEntry)
                    Dim idMokh As Integer = CInt(Partager.deClt.Key)

                    dossAvo = New dossier_Avocat_Mokhabara(idMokh, Partager.idAvoDoss, True)
                    partager.dv.Ajouter_Dos_Avo_Bur_Mokh(dossAvo)
                    remplirMaListMokhabara()
                    MsgBox("تمت إضافة المحامي للملف بنجاح", MsgBoxStyle.Information, "نجاح")
                End If

            End If
        Catch sqlEx As SqlException
            If sqlEx.Message.Contains("PK_dossier_Avocat_Mokhabara") Then
                MsgBox("عفوا، محامي المخابرة تمت إضافته لهذاالملف من قبل", MsgBoxStyle.Critical, "خطأ")
            Else
                MsgBox(sqlEx.Message)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Btn_supp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_supp.Click
        If List_tous.SelectedIndices.Count > 0 Then
            If MsgBox("هل تريد فعلا حذف هذا المحامي من هذا الملف ؟", MsgBoxStyle.YesNo Or MsgBoxStyle.Information, "إضافة") = MsgBoxResult.Yes Then
                dossAvo = partager.dv.List_Mokhabara(List_tous.SelectedIndices.Item(0))
                partager.dv.suprimmer_Dos_Avo_Bur_Mokh(dossAvo)
                partager.dv.remplir_List_avocat_bureau()
                remplirMokhabara()
                List_tous.Items.Clear()
                remplirMaListMokhabara()
                MsgBox("عملية الحذف تمت بنجاح", MsgBoxStyle.Information, "نجاح")
            End If
        Else
            MsgBox("اختر محامي من القائمة", MsgBoxStyle.Information, "خطأ")
        End If

    End Sub

    Private Sub List_tous_ItemChecked(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles List_tous.ItemChecked
        If Partager.checkHand Then
            Dim i As Integer = 0
            For Each item1 As ListViewItem In List_tous.Items
                dossAvo = New dossier_Avocat_Mokhabara
                dossAvo = partager.dv.List_Mokhabara(i)
                dossAvo.nomme = item1.Checked
                partager.dv.modifierAvoMokhNomme(dossAvo)
                i += 1
            Next
        End If
    End Sub

End Class